package cn.campus.util;

import lombok.extern.slf4j.Slf4j;

import java.io.*;

/**
 * 文件工具类
 * Created by linyanbin on 2018/9/22.
 */
@Slf4j
public class FileUtils {
    private FileUtils(){}

    public static String readTxtToString(String realPath) {
        File file = new File(realPath);
        StringBuilder sb = new StringBuilder();
        if (!file.exists()) {
            return null;
        }
        try {
            try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)))){
                String line = "";
                line = reader.readLine();
                while (line != null) {
                    sb.append(line);
                    line = reader.readLine();
                }
            }
        } catch (FileNotFoundException e) {
            log.error("读取文件失败, {}", e);
        } catch (IOException e) {
            log.error("读取文件失败, {}", e);
        }
        return sb.toString();
    }
}
